How to handle edge cases of stack

welcome to shbcf.ru